//
//  JYTLearnCarViewController.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 16/12/14.
//  Copyright © 2016年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTLearnCarViewController.h"
#import "JYTADSView.h"
#import "Feature.h"
#import "JYTFeaturesCell.h"
#import "JYTTestViewController.h"
#import "JYTSchoolViewController.h"
#import "JYTAppointViewController.h"
#import "JYTLoginViewController.h"
#import "JYTCoachViewController.h"
#define AdsViewH (170)

@interface JYTLearnCarViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, weak) JYTADSView * adsView;

@property (nonatomic, strong)NSMutableArray * features;
@property (nonatomic, strong)UITableView *tab;

@end

@implementation JYTLearnCarViewController

-(NSMutableArray *)features
{
    if (_features == nil) {
        _features = [NSMutableArray array];
    }
    
    return _features;
}

static NSString *YGXFeatureCellId = @"Feature";
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    [self setNavgationBarView:@{@"pageTitle":@"驾通易", @"lftBtnTitle":@"no", @"rhtBtnTitle":@"no"}];
    //return;
    [self addADSView];
    
    [self addFeatureView];
    
    NSArray *dateSource =@[@{@"header":@"ic_home_zjx", @"name":@"找驾校", @"sign":@"驾校权威认证, 口碑好, 通过率高, 拿照快."},
                           @{@"header":@"ic_home_zjl", @"name":@"找教练", @"sign":@"虚心教学, 认真严谨, 好评率高, 快乐拿本."},
                           @{@"header":@"ic_home_zpl", @"name":@"找陪练", @"sign":@"耐心细致, 态度好服务棒."},
                           @{@"header":@"ic_home_yx", @"name":@"预约", @"sign":@"智能预约, 方便快捷, 价格透明, 学时付款."}
                           ];
    
    NSArray * all = [Feature mj_objectArrayWithKeyValuesArray:dateSource];
    [self.features addObjectsFromArray:all];
    [self.tab reloadData];

    [self addFeatureView];


}

- (void)addADSView
{
    CGFloat adsViewY = NAVIGATION_BAR_HEIGHT + STATUS_BAR_HEIGHT;
    
    
    JYTADSView * adsView = [JYTADSView adsViewWithFrame:CGRectMake(0, adsViewY, CURRENT_SCREEN_WIDTH, AdsViewH)];
    self.adsView = adsView;
    [self.view addSubview:adsView];
    
    adsView.imagesName = @[@"01首页_06",@"3",@"01首页_06"];
    
    [adsView setAdsViewDidSelectedBlock:^(JYTADSView * adsView, NSInteger index, NSString * imageName)
     {
         NSLog(@"block 点击 %@",imageName);
     }];
    
}


- (void)addFeatureView
{
    
    CGFloat featureViewY = NAVIGATION_BAR_HEIGHT + STATUS_BAR_HEIGHT + AdsViewH;
    CGFloat featureViewH = NAVIGATION_BAR_HEIGHT + AdsViewH + TAB_BAR_HEIGHT;
    UITableView *tab = [[UITableView alloc]initWithFrame:CGRectMake(0, featureViewY, CURRENT_SCREEN_WIDTH, CURRENT_SCREEN_HEIGHT - featureViewH) style:UITableViewStylePlain];
    tab.delegate = self;
    tab.dataSource = self;
    self.tab = tab;
    
    [self.tab registerNib:[UINib nibWithNibName:NSStringFromClass([JYTFeaturesCell class]) bundle:nil] forCellReuseIdentifier:YGXFeatureCellId];
    [self.view addSubview:tab];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.features.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    
    JYTFeaturesCell *cell = [tableView dequeueReusableCellWithIdentifier:YGXFeatureCellId];
    
    cell.feature = self.features[indexPath.row];
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 68.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BOOL isUsedOffLine = [[JYTUserManager shared] isUsedOffLine];
    
    if (indexPath.row == 0) {
        
        JYTSchoolViewController *s = [[JYTSchoolViewController alloc]init];
        [self pushViewControllerToContainer:s];
    }else if (indexPath.row == 3){//预约
        if (!isUsedOffLine) {
            [self pushViewControllerToContainer:[[JYTAppointViewController alloc] init]];
        }else{
            [self pushViewControllerToContainer:[[JYTLoginViewController alloc] init]];
                    }
    }else if(indexPath.row == 1){
        JYTCoachViewController *coach = [[JYTCoachViewController alloc]init];
        [self pushViewControllerToContainer:coach];

    }else {
        JYTTestViewController *t = [[JYTTestViewController alloc]init];
        [self pushViewControllerToContainer:t];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
